package cn.tedu.myweb.controller;

import cn.tedu.myweb.exception.ServiceException;
import cn.tedu.myweb.mapper.ChatsMapper;
import cn.tedu.myweb.mapper.UserMapper;
import cn.tedu.myweb.model.Chats;
import cn.tedu.myweb.model.Friends;
import cn.tedu.myweb.model.User;
import cn.tedu.myweb.service.IFriendsService;
import cn.tedu.myweb.service.IUserService;
import cn.tedu.myweb.vo.ChatVo;
import cn.tedu.myweb.vo.FriendVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/v1/friends")
@Slf4j
public class FriendsController {
    @Autowired
    private IFriendsService friendsService;

    @Autowired
    private IUserService userService;

    @GetMapping("/my")
    public List<Friends> my(
            @AuthenticationPrincipal UserDetails user){
        List<Friends> friends = friendsService.getMyFriend(user.getUsername());
        return friends;
    }

    @GetMapping("/{id}")
    public User stranger(
            @PathVariable String id){
        User user = userService.addFriendsByName(id);
        if(user==null){
            user=userService.addFriendsByPhone(id);
            if(user==null){
                return null;
            }
        }
        return user;
    }



}
